+2007-12-13 Kristian Rietveld <kris@imendio.com>
+
+ * gtk/tests/liststore.c:
+ * gtk/tests/treestore.c: test the move and swap functions on a
+ store with only one node.
+
2007-12-13 Kristian Rietveld <kris@imendio.com>
* gtk/gtktestutils.c (gtk_test_init): add a call to
*/
/* To do:
- * - We probably want to do all move and swap tests on a 1-item list store
- * also.
* - Test implementations of the interfaces: DnD, sortable, buildable
* and the tree model interface itself?
* - Need to check if the emitted signals are right.
check_model (fixture, new_order, -1);
}
+static void
+list_store_test_swap_single (void)
+{
+ GtkTreeIter iter;
+ GtkTreeIter iter_copy;
+ GtkListStore *store;
+
+ store = gtk_list_store_new (1, G_TYPE_INT);
+
+ /* Check if swap on a store with a single node does not corrupt
+ * the store.
+ */
+
+ gtk_list_store_append (store, &iter);
+ iter_copy = iter;
+
+ gtk_list_store_swap (store, &iter, &iter);
+ g_assert (iters_equal (&iter, &iter_copy));
+ g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+ g_assert (iters_equal (&iter, &iter_copy));
+
+ g_object_unref (store);
+}
+
/* move after */
static void
check_model (fixture, new_order, -1);
}
+static void
+list_store_test_move_after_single (void)
+{
+ GtkTreeIter iter;
+ GtkTreeIter iter_copy;
+ GtkListStore *store;
+
+ store = gtk_list_store_new (1, G_TYPE_INT);
+
+ /* Check if move-after on a store with a single node does not corrupt
+ * the store.
+ */
+
+ gtk_list_store_append (store, &iter);
+ iter_copy = iter;
+
+ gtk_list_store_move_after (store, &iter, NULL);
+ g_assert (iters_equal (&iter, &iter_copy));
+ g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+ g_assert (iters_equal (&iter, &iter_copy));
+
+ gtk_list_store_move_after (store, &iter, &iter);
+ g_assert (iters_equal (&iter, &iter_copy));
+ g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+ g_assert (iters_equal (&iter, &iter_copy));
+
+ g_object_unref (store);
+}
+
/* move before */
static void
check_model (fixture, new_order, -1);
}
+static void
+list_store_test_move_before_single (void)
+{
+ GtkTreeIter iter;
+ GtkTreeIter iter_copy;
+ GtkListStore *store;
+
+ store = gtk_list_store_new (1, G_TYPE_INT);
+
+ /* Check if move-before on a store with a single node does not corrupt
+ * the store.
+ */
+
+ gtk_list_store_append (store, &iter);
+ iter_copy = iter;
+
+ gtk_list_store_move_before (store, &iter, NULL);
+ g_assert (iters_equal (&iter, &iter_copy));
+ g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+ g_assert (iters_equal (&iter, &iter_copy));
+
+ gtk_list_store_move_before (store, &iter, &iter);
+ g_assert (iters_equal (&iter, &iter_copy));
+ g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+ g_assert (iters_equal (&iter, &iter_copy));
+
+ g_object_unref (store);
+}
+
/* main */
int
g_test_add ("/list-store/swap-end", ListStore, NULL,
list_store_setup, list_store_test_swap_end,
list_store_teardown);
+ g_test_add_func ("/list-store/swap-single",
+ list_store_test_swap_single);
/* moving */
g_test_add ("/list-store/move-after-from-start", ListStore, NULL,
g_test_add ("/list-store/move-after-NULL", ListStore, NULL,
list_store_setup, list_store_test_move_after_NULL,
list_store_teardown);
+ g_test_add_func ("/list-store/move-after-single",
+ list_store_test_move_after_single);
g_test_add ("/list-store/move-before-next", ListStore, NULL,
list_store_setup, list_store_test_move_before_next,
g_test_add ("/list-store/move-before-NULL", ListStore, NULL,
list_store_setup, list_store_test_move_before_NULL,
list_store_teardown);
+ g_test_add_func ("/list-store/move-before-single",
+ list_store_test_move_before_single);
return g_test_run ();
}
check_model (fixture, new_order, -1);
}
+static void
+tree_store_test_swap_single (void)
+{
+ GtkTreeIter iter;
+ GtkTreeIter iter_copy;
+ GtkTreeStore *store;
+
+ store = gtk_tree_store_new (1, G_TYPE_INT);
+
+ /* Check if swap on a store with a single node does not corrupt
+ * the store.
+ */
+
+ gtk_tree_store_append (store, &iter, NULL);
+ iter_copy = iter;
+
+ gtk_tree_store_swap (store, &iter, &iter);
+ g_assert (iters_equal (&iter, &iter_copy));
+ g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+ g_assert (iters_equal (&iter, &iter_copy));
+
+ g_object_unref (store);
+}
+
/* move after */
static void
check_model (fixture, new_order, -1);
}
+static void
+tree_store_test_move_after_single (void)
+{
+ GtkTreeIter iter;
+ GtkTreeIter iter_copy;
+ GtkTreeStore *store;
+
+ store = gtk_tree_store_new (1, G_TYPE_INT);
+
+ /* Check if move-after on a store with a single node does not corrupt
+ * the store.
+ */
+
+ gtk_tree_store_append (store, &iter, NULL);
+ iter_copy = iter;
+
+ gtk_tree_store_move_after (store, &iter, NULL);
+ g_assert (iters_equal (&iter, &iter_copy));
+ g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+ g_assert (iters_equal (&iter, &iter_copy));
+
+ gtk_tree_store_move_after (store, &iter, &iter);
+ g_assert (iters_equal (&iter, &iter_copy));
+ g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+ g_assert (iters_equal (&iter, &iter_copy));
+
+ g_object_unref (store);
+}
+
/* move before */
static void
check_model (fixture, new_order, -1);
}
+static void
+tree_store_test_move_before_single (void)
+{
+ GtkTreeIter iter;
+ GtkTreeIter iter_copy;
+ GtkTreeStore *store;
+
+ store = gtk_tree_store_new (1, G_TYPE_INT);
+
+ /* Check if move-after on a store with a single node does not corrupt
+ * the store.
+ */
+
+ gtk_tree_store_append (store, &iter, NULL);
+ iter_copy = iter;
+
+ gtk_tree_store_move_before (store, &iter, NULL);
+ g_assert (iters_equal (&iter, &iter_copy));
+ g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+ g_assert (iters_equal (&iter, &iter_copy));
+
+ gtk_tree_store_move_before (store, &iter, &iter);
+ g_assert (iters_equal (&iter, &iter_copy));
+ g_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter));
+ g_assert (iters_equal (&iter, &iter_copy));
+
+ g_object_unref (store);
+}
+
/* main */
int
g_test_add ("/tree-store/swap-end", TreeStore, NULL,
tree_store_setup, tree_store_test_swap_end,
tree_store_teardown);
+ g_test_add_func ("/tree-store/swap-single",
+ tree_store_test_swap_single);
/* moving */
g_test_add ("/tree-store/move-after-from-start", TreeStore, NULL,
g_test_add ("/tree-store/move-after-NULL", TreeStore, NULL,
tree_store_setup, tree_store_test_move_after_NULL,
tree_store_teardown);
+ g_test_add_func ("/tree-store/move-after-single",
+ tree_store_test_move_after_single);
g_test_add ("/tree-store/move-before-next", TreeStore, NULL,
tree_store_setup, tree_store_test_move_before_next,
g_test_add ("/tree-store/move-before-NULL", TreeStore, NULL,
tree_store_setup, tree_store_test_move_before_NULL,
tree_store_teardown);
+ g_test_add_func ("/tree-store/move-before-single",
+ tree_store_test_move_before_single);
return g_test_run ();
}